package com.ctrip.ec.biz.dao.goods;
import com.ctrip.ec.biz.entity.brand.BrandEntity;
import com.ctrip.ec.biz.entity.goods.GoodsCategoryEntity;
import com.ctrip.ec.biz.entity.goods.GoodsEntityEx;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.goods.GoodsEntity;
import com.ctrip.ec.dal.DbAccess;
import com.ctrip.ec.dal.EntityBase;
import com.ctrip.ec.dal.PagerSetting;
import org.junit.Test;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class GoodsDao extends DaoBase<GoodsEntity> {
    public GoodsDao() {
        super(GoodsEntity.class);
    }
    public GoodsDao(DbAccess db) {
        super(GoodsEntity.class,db);
    }


    public List<GoodsEntityEx> listEx(PagerSetting pagerSetting,Object... paras) throws SQLException {
        String select = "select *, (select name from " + EntityBase.getTableName(GoodsCategoryEntity.class) +
                " where id = " + this.getTableName() + ".cat_id ) as cat_name,(select name from " + EntityBase.getTableName(BrandEntity.class) +
                " where id = " + this.getTableName() + ".brand_id) as brand_name from " + this.getTableName();

        pagerSetting.setSelect(select);
        String sql = pagerSetting.buildPagerSql(this,paras);

        return this.db.query(GoodsEntityEx.class, sql, paras);
    }
}
